<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- android.qdoc -->
  <title>Adding OpenSSL Support for Android | Qt 5.14</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.14</a></td><td >Adding OpenSSL Support for Android</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.14.2 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Adding OpenSSL Support for Android</h1>
<span class="subtitle"></span>
<!-- $$$android-openssl-support.html-description -->
<div class="descr"> <a name="details"></a>
<p>The Qt installation package comes with OpenSSL support but the OpenSSL libraries are not part of the package due to legal restrictions in some countries. If your application depends on OpenSSL, consider packaging the SSL libraries with your Application Package (APK) as the target device may or may not have them. You can use the <a href="../qtnetwork/qsslsocket.html#supportsSsl">QSslSocket::supportsSsl</a>() static function to check for SSL support on the target.</p>
<p>The following instructions guide you to build and add the OpenSSL libraries to the APK:</p>
<ol class="1" type="1"><li>Download the latest OpenSSL 1.1&#x2e;x sources from <a href="http://www.openssl.org/source">http://www.openssl.org/source</a>.</li>
<li>Extract the sources to a folder and navigate to that folder using the CLI.<p><b>Note: </b>If your development platform is Windows, you need <code>msys</code> with <code>perl</code> v5.14 or later to build OpenSSL.</p></li>
<li>Add android llvm toolchain to your path:<pre class="cpp plain">

  export PATH=&quot;&lt;android_ndk_path&gt;/toolchains/llvm/prebuilt/&lt;host&gt;/bin&quot;:$PATH

</pre>
</li>
<li>Configure the OpenSSL sources to build for Android using the following command:<pre class="cpp plain">

  ./Configure shared android-&lt;arch&gt; -D__ANDROID_API__=21

</pre>
<p><b>Note: </b>You must consider enabling/disabling the SSL features based on the legal restrictions in the region where your application is available. See the <a href="http://wiki.openssl.org/index.php/Compilation_and_Installation#Configure_Options">SSL configure options</a> for details about the configurable features.</p></li>
<li>Run <code>make SHLIB_VERSION_NUMBER= SHLIB_EXT=_1_1.so build_libs</code> to build <code>libcrypto</code> and <code>libssl</code> shared libraries that are not versioned, but with a <i>_1_1</i> suffix. If you want to use a different suffix, then you must set the <code>ANDROID_OPENSSL_SUFFIX</code> environment variable before you access the Qt Network API. Without a suffix, Android 5 (API 21) will load the system libraries <i>libcrypto.so</i> and <i>libssl.so</i>, which are OpenSSL 1.0, rather than your libraries.<p><b>Note: </b>Android does not load versioned libraries.</p></li>
<li>Open your Qt project using Qt Creator and update the &quot;Build Android APK&quot; settings to add <i>libcrypto</i> and <i>libssl</i> as additional libraries for your project.</li>
<li>Run your application to see it running on the device.</li>
</ol>
<p><b>Note: </b>here <a href="https://github.com/KDAB/android_openssl">https://github.com/KDAB/android_openssl</a> you can find a script which can be used to compile openssl for all android abis and also latest prebuilt libs.</p><p>Qt Creator builds your application and creates an application package (APK) with the OpenSSL libraries bundled in it. Once the APK is ready, it uses <code>adb</code> to deploy the APK on the target you chose and launch the application.</p>
</div>
<!-- @@@android-openssl-support.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
